﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System.IO;
using TotalApplication.Core;

namespace TotalApplication.viewmodels
{
    public partial class FileViewModel : BaseViewModel
    {
        #region Properties

        [ObservableProperty]
        private string _title = "Personal Tools";

        [ObservableProperty]
        private string _replacePart = "";

        [ObservableProperty]
        private string _path = "";

        #endregion

        #region Constructor

        /// <summary>
        /// Default constructor
        /// </summary>
        public FileViewModel()
        {

        }

        #endregion

        #region Commands

        [RelayCommand]
        private void Confirm()
        {
            // Implement the logic for the Confirm command here
            if (File.Exists(Path))
            {
                File.Move(Path, Path.Replace(ReplacePart, ""));
            }
            else if (Directory.Exists(Path))
            {
                foreach (var file in Directory.GetFiles(Path, "*", SearchOption.AllDirectories))
                {
                    File.Move(file, file.Replace(ReplacePart, ""));
                }
            }
        }

        #endregion
    }
}
